package com.anssy.voteballot.utils;

import android.text.TextUtils;

import com.anssy.voteballot.bean.base.BaseRes;
import com.blankj.utilcode.util.ToastUtils;
import com.google.gson.Gson;

import java.io.IOException;

import okhttp3.ResponseBody;
import retrofit2.Response;

public class HttpUtils {

    public static BaseRes parseResponse(Response<ResponseBody> response, Class<?> baseResClass) {
        if (response.isSuccessful()) {
            try {
                if (response.body() != null) {
                    String result = response.body().string();
                    if (!TextUtils.isEmpty(result)) {
                        return (BaseRes) new Gson().fromJson(result, baseResClass);
                   /*     if (baseRes.getCode() == 0) {
                            return baseRes;
                        } else {
                            ToastUtils.showShort(baseRes.getMsg());
                            return null;
                        }*/
//                        } else if (baseRes.getCode() != 0) {
//                            ToastUtils.showShort(baseRes.getMsg());
//                            return null;
//                        }
                    }
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        return null;
    }
}
